package com.demo.niodemo;

import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NIOFileWriteDemo {

	public static void main(String[] args) throws IOException {
		String fileName = "/home/admin/develop/workspace/nio-demo/src/main/resources/testdata.txt";
		writeByFileOutputStream(fileName, "dsvggb");
	}
	
	public static void writeByFileOutputStream(String fileName, String data) throws IOException{
		FileOutputStream fos = new FileOutputStream(fileName, true);
		FileChannel foutChannel = fos.getChannel();
		ByteBuffer bb = ByteBuffer.allocate(1024);
		bb.put(data.getBytes());
		bb.flip();
		foutChannel.write(bb);
		foutChannel.close();
		fos.close();
	}

}
